<?php
include("./config/session.php");
include("./class/template.inc");
include("./config/QuickMySQL.php");
include("config/config.inc.php");

class CUserQQ extends PageBase
{
	function OnPageLoad(){
		$tpl = new Template("./ui/");
		$tpl->set_file("main", "user-qq-test.html");
		$tpl->pparse("out", "main");
	}
	/*请求数据*/
	function OnGetData(){
		$ret = array("total" => 0, "rows" => array());
		$cnn = new QuickMySQL();
		if( $cnn->mysql ){
			/*连接数据库成功，查询相关数据*/
			$page = (int)$_POST["page"] - 1;
			$pagesize = (int)$_POST["rows"];
			if( $page < 0 ) $page = 0;
			if( $pagesize < 1 ) $pagesize = 1;
			$start = $page * $pagesize;
			/* 构造查询语句 */
/*			$sql = "select id, ifnull(qq, ''), ifnull(name, ''), ifnull(gwlogin, ''), ifnull(getdt, '')"
				. " , gwbuy, concat(sem_s, '/', sem_f), concat(sms_s, '/', sms_f), concat(mms_s, '/', mms_f)"
				. " from t_user_qq limit {$start},{$pagesize}";*/
			$sql = "select id, ifnull(qq, ''), ifnull(name, ''), ifnull(license, ''), ifnull(fistdt, '')"
				. " , active, concat(sem_s, '/', sem_f), concat(sms_s, '/', sms_f), concat(mms_s, '/', mms_f)"
				. " from t_user_qq2_test limit {$start},{$pagesize}";
			if( $res = mysql_query($sql, $cnn->mysql) ){
				while( $row = mysql_fetch_row($res) ){
					array_push($ret["rows"], array(
								"id" => $row[0]
								, "qq" => $row[1]
								, "name" => $row[2]
								, "gwlogin" => $row[3]
								, "getdt" => $row[4]
								, "gwbuy" => $row[5]
								, "sem" => $row[6]
								, "sms" => $row[7]
								, "mms" => $row[8]			
								));	
				}
				mysql_free_result($res);
			}
			/*查询总个数*/
			$ret["total"] = $cnn->getTableCount("t_user_qq2_test");
		}
		
		$ret_json = json_encode($ret);
		echo $ret_json;
	}
}

$cc = new CUserQQ();
?>